package cn.yunhe.service.serviceImpl;

import cn.yunhe.dao.ExamDao;
import cn.yunhe.entity.Exam;
import cn.yunhe.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("examService")
public class ExamserviceImpl implements ExamService {
    @Autowired
    @Qualifier("examDao")
    private ExamDao examDao;
//模拟
    @Override
    public List<Exam> getExamList() {
        return examDao.getExamList();
    }
//正常考试试卷
    @Override
    public List<Exam> getExamination() {
        return examDao.getExamination();
    }
//获取考试的申请
    @Override
    public List<Exam> getApplyTest(int userId) {
        updAllExamAudit();
        return examDao.getApplyTest(userId);
    }

    @Override
    public int updExamAudit(Exam exam) {
        return examDao.updExamAudit(exam);
    }

    @Override
    public int addApply(Map map) {
        return examDao.addApply(map);
    }

    @Override
    public List<Exam> getExamListToApply(int userId) {
        return examDao.getExamListToApply(userId);
    }

    @Override
    public List<Map<String, Object>> getCurrUserExam(int userId) {
        return examDao.getCurrUserExam(userId);
    }

    @Override
    public List<Exam> getAllSimulate() {
        return examDao.getAllSimulate();
    }

    @Override
    public int updAllExamAudit() {
        Exam exam = new Exam();
        byte b = 1;
        exam.setApproved(b);
        List<Exam>list = examDao.getAllExam(exam);
        Date date = new Date();
        int count = 0;
        for(Exam e : list){
            if(date.getTime() >= (e.getEndTime()).getTime()){
                count += examDao.updAllExamAudit(e.getId());
            }
        }
        return count;
    }

    @Override
    public Exam getExamById(int id) {
        return examDao.getExamById(id);
    }

    @Override
    public int updUser2Exam(Map map) {
        return examDao.updUser2Exam(map);
    }

}
